%
%
%  Intensity calculation for Imaris
%
%
%  Installation:
%
%  - Copy this file into the XTensions folder in the Imaris installation directory
%  - You will find this function in the Image Processing menu
%
%    <CustomTools>
%      <Menu>
%       <Submenu name="McGill">
%        <Item name="Set last z slide to black" icon="Matlab" tooltip="Use this to clear the last z slide of the first channel of any imaging errors">
%          <Command>Matlab::MGDeleteLastZSlide(%i)</Command>
%        </Item>
%       </Submenu>
%      </Menu>
%    </CustomTools>
%  
%
%  Description:
%
%   Clears the last z slide of the first channel since sometimes there are 
%   errors present on that slide.
%   Author: Hendrik Golzke, Patrik Rath
%   Last change: 2010-08-20
%
%

function MGIntensity(aImarisApplicationID)

    % connect to Imaris Com interface
    if ~isa(aImarisApplicationID, 'COM.Imaris_Application')
      vImarisServer = actxserver('ImarisServer.Server');
      if ischar(aImarisApplicationID)
        aImarisApplicationID = round(str2double(aImarisApplicationID));
      end
      apImaris = vImarisServer.GetObject(aImarisApplicationID);
    else
      apImaris = aImarisApplicationID;
    end
    
    %Set undo point
    apImaris.DataSetPushUndo('Set last slide to zero');
    %Load Data (Channels)
    dsChannels = apImaris.mDataSet;
    %Get data like dimensions &c.
    struChannels = dsChannels.get;

    %Set last slice to zero
    for iChannel=0:(struChannels.mSizeC-1)
        dsChannels.SetDataSlice(uint16(zeros(struChannels.mSizeX,struChannels.mSizeY)),struChannels.mExtendMaxZ-1, iChannel, 0);
    end;
    
end